package com.dwms.controller;

import com.dwms.entity.PageResponse;
import com.dwms.entity.QueryRequest;
import com.dwms.entity.Result;
import com.dwms.entity.base.brand.request.BrandQueryRequest;
import com.dwms.entity.base.brand.request.BrandRequest;
import com.dwms.entity.base.brand.response.BrandResponse;
import com.dwms.feign.goods.BrandFeignClient;
import com.dwms.utils.WebUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: BrandController
 * @Description: Brand
 * @Create 2025-08-27 14:39:43
 * @Author WH
 * @Since 1.0.0
**/
@Tag(name = "品牌管理")
@RestController
@RequestMapping(value = "/goods/brand")
@RequiredArgsConstructor
public class BrandController {

    private final HttpServletRequest request;
    private final BrandFeignClient brandFeignClient;

    /**
     * 保存
     *
     * @param brandRequest
     *          请求参数
     * @return
     */
    @Operation(summary = "新增品牌")
    @PostMapping("/save")
    public Result save(@RequestBody BrandRequest brandRequest) {
        WebUtil.getAdminRequest(request,brandRequest);
        return brandFeignClient.save(brandRequest);
    }

    /**
     * 修改
     *
     * @param brandRequest
     *          请求参数
     * @return
     */
    @Operation(summary = "修改品牌")
    @PostMapping("/update")
    public Result update(@RequestBody BrandRequest brandRequest) {
        WebUtil.getAdminRequest(request,brandRequest);
        return brandFeignClient.update(brandRequest);
    }
    

    /**
     * 分页查询
     *
     * @param query
     *          查询参数
     * @return
     */
    @Operation(summary = "分页查询")
    @PostMapping("/findPage")
    public Result<PageResponse<BrandResponse>> findPage(@RequestBody BrandQueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return brandFeignClient.findPage(query);

    }

    /**
     *  根据ID查询
     *
     * @param query
     *          参数
     * @return
     */
    @Operation(summary = "根据ID查询")
    @PostMapping("/findById")
    public Result findById(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return this.brandFeignClient.findById(query);

    }

    /**
     * 删除
     *
     * @param query
     *          ID
     * @return
     */
    @Operation(summary = "删除品牌")
    @PostMapping("/delete")
    public Result delete(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return this.brandFeignClient.delete(query);
    }

    /**
     * 查询列表
     * @param query
     * @return
     */
    @Operation(summary = "查询列表")
    @PostMapping("/findList")
    public Result<List<BrandResponse>> findList(@RequestBody BrandQueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return this.brandFeignClient.findList(query);
    }
}
